from bisect import bisect_right, bisect_left
from collections import defaultdict
from typing import List


class RangeFreqQuery:

    def __init__(self, arr: List[int]):
        map = defaultdict(list)
        for i, val in enumerate(arr):
            map[val].append(i)
        self.map = map

    def query(self, left: int, right: int, value: int) -> int:
        v = self.map[value]
        return bisect_right(v, right) - bisect_left(v, left)